/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.laporanrkaunit;

import java.util.HashMap;

//////////
import java.util.Map;

import org.sadhar.sia.framework.ClassApplicationModule;

import org.zkoss.zul.Button;

import net.sf.jasperreports.engine.data.JRTableModelDataSource;
import org.sadhar.sia.common.ClassConnection;
import org.sadhar.sia.common.ClassSession;
import org.sadhar.sipp.laporananggaranpendapatanuangformulirmahasiswabaru.ResultSetTableModel;
import org.sadhar.sipp.unkerja.UnKerja;
import org.sadhar.sipp.unkerja.UnKerjaDAO;
import org.sadhar.sipp.unkerja.UnKerjaDAOImpl;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zkex.zul.Jasperreport;
import org.zkoss.zul.Panel;
import org.zkoss.zul.Tabbox;

/**
 *
 * @author Yohan Hardinugroho
 */
public class LaporanRKAUnitWnd extends ClassApplicationModule {

    private Label lblTahunAnggaran;
    private Label lblUnitKerja;
    private Button buttonHideExport;
    private Jasperreport report;
    private Jasperreport report2;
    private Listbox lstboxformat;
    private Tabbox tbboxLaporan;
    private ClassSession session;
    private LaporanRKAUnitDAO laporanRKAUnitDAO;
    private UnKerjaDAO unKerjaDAO;

    public LaporanRKAUnitWnd() {
        session = new ClassSession("2009", "02001000");
        laporanRKAUnitDAO = new LaporanRKAUnitDAOImpl();
        unKerjaDAO = new UnKerjaDAOImpl();
    }

    public void onCreate() throws Exception {

        lblTahunAnggaran = (Label) getFellow("lblTahunAnggaran");
        lblUnitKerja = (Label) getFellow("lblUnitKerja");
        tbboxLaporan = (Tabbox) getFellow("tbboxLaporan");
        report = (Jasperreport) getFellow("report");
        report2 = (Jasperreport) getFellow("report2");
        lstboxformat = (Listbox) getFellow("lstboxformat");
        buttonHideExport = (Button) getFellow("buttonHideExport");
        lblTahunAnggaran.setValue(session.getThnAnggaran());
        UnKerja uk = unKerjaDAO.select(session.getKodeUnit());
        lblUnitKerja.setValue(uk.getNamaUnitKerja());
        load();
    }

    public void load() {
    }

    public void showExport() {
        tbboxLaporan.setVisible(true);
        buttonHideExport.setVisible(true);
    }

    public void hideExport() {
        tbboxLaporan.setVisible(false);
        buttonHideExport.setVisible(false);
    }

    public void export() throws Exception {
        String tahunKelompok = laporanRKAUnitDAO.tahunKelompokAnggaranYangDigunakan(session.getThnAnggaran());
        String sql = laporanRKAUnitDAO.getQueryRKA(session.getThnAnggaran(), tahunKelompok, session.getKodeUnit());
        report.setType(lstboxformat.getSelectedItem().getValue().toString());
        report.setSrc("reports/laporanrkaunit/LaporanRKAUnit.jasper");
        Map m = new HashMap();
        m.put("tahunAnggaran", session.getThnAnggaran());
        report.setParameters(m);
        ResultSetTableModel rstm = new ResultSetTableModel(ClassConnection.getJdbc().getDataSource().getConnection(), sql);

        report.setDatasource(new JRTableModelDataSource(rstm));

        String sqlInd = laporanRKAUnitDAO.getQueryIndiktor(session.getThnAnggaran(), session.getKodeUnit());
        report2.setType(lstboxformat.getSelectedItem().getValue().toString());
        report2.setSrc("reports/laporanrkaunit/DaftarIndikatorKinerja.jasper");
        report2.setParameters(m);
        rstm = new ResultSetTableModel(ClassConnection.getJdbc().getDataSource().getConnection(), sqlInd);
        report2.setDatasource(new JRTableModelDataSource(rstm));
        showExport();
    }
}

